﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MySkiPatrolSite.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        ArticleSvc.ArticleClient svc = new ArticleSvc.ArticleClient();

        public ActionResult Index()
        {

            ArticleSvc.ArticleList articleList = null;

            //we simply load the web articles...and only display what is intended for the VIEW (public or private)
            if(Session["PATROL"] != null)
            {
                MySkiPatrolSite.ArticleSvc.ArticleRequest request = new ArticleSvc.ArticleRequest();
                request.DataTransaction = new ArticleSvc.DataTransaction();
                request.DataTransaction.PatrolPrefix = ((MySkiPatrolSite.AdminSvc.Patrol)Session["PATROL"]).dbPrefix;
                request.PageName = "Home";

                if ((Session["MEMBER"] == null) || (!Security.IsLoggedIn((MembershipSvc.Member)Session["MEMBER"])))
                {
                    request.Public = true;
                }

                articleList = svc.GetArticles(request);
                
            }


            ViewData["Message"] = string.Empty;
            ViewData["Articles"] = articleList;
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult NotAuthorized()
        {
            return View();
        }
    }
}
